package com.c2b.algorithm.leetcode.hot100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <a href="https://leetcode.cn/problems/letter-combinations-of-a-phone-number/">电话号码的字母组合</a>
 * <p>给定一个仅包含数字 2-9 的字符串，返回所有它能表示的字母组合。答案可以按 任意顺序 返回。
 * 给出数字到字母的映射如下（与电话按键相同）。注意 1 不对应任何字母。</p>
 *
 * @author c2b
 * @since 2023/4/18 18:55
 */
public class Hot017LetterCombinations_M {

    public List<String> letterCombinations(String digits) {
        return letterCombinations(digits, new ArrayList<>());
    }

    private List<String> letterCombinations(String digits, List<String> paramList) {
        if (digits.length() == 0) {
            return paramList;
        }
        char charAt = digits.charAt(0);
        List<String> characterList = new ArrayList<>();
        switch (charAt) {
            case '2':
                characterList = Arrays.asList("a", "b", "c");
                break;
            case '3':
                characterList = Arrays.asList("d", "e", "f");
                break;
            case '4':
                characterList = Arrays.asList("g", "h", "i");
                break;
            case '5':
                characterList = Arrays.asList("j", "k", "l");
                break;
            case '6':
                characterList = Arrays.asList("m", "n", "o");
                break;
            case '7':
                characterList = Arrays.asList("p", "q", "r", "s");
                break;
            case '8':
                characterList = Arrays.asList("t", "u", "v");
                break;
            case '9':
                characterList = Arrays.asList("w", "x", "y", "z");
                break;
            default:
        }
        List<String> resultList = new ArrayList<>();
        if (paramList.isEmpty()) {
            resultList.addAll(characterList);
        } else {
            for (String param : paramList) {
                for (String character : characterList) {
                    resultList.add(param + character);
                }
            }
        }
        return letterCombinations(digits.substring(1), resultList);
    }

    public static void main(String[] args) {
        Hot017LetterCombinations_M hot017LetterCombinations_m = new Hot017LetterCombinations_M();
        for (String letterCombination : hot017LetterCombinations_m.letterCombinations("")) {
            System.out.println(letterCombination);
        }
    }
}
